#!/usr/bin/env python
#coding=utf-8

import eventlet,re
from eventlet.green import urllib2

url_list = ['http://www.douban.com/']

def fetch(url):
    buf = urllib2.urlopen(url).read()
    # print url, len(buf)
    return url, buf

def async_fetch(url_list):
    pool = eventlet.GreenPool(50)
    list_buf = []
    for url, buf in pool.imap(fetch, url_list):
        print url, buf
        # print buf
        list_buf.append(buf)

    set_url = set()
    for buf in list_buf:
        list_url = re.findall('<a href="(http.*?)"', buf)
        set_url |= set(list_url)
    print '\n'.join(set_url)
    return list(set_url)

if __name__ == '__main__':
	# fetch(url_list[0])
	async_fetch(url_list)